<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>getOwnPropertyDescriptor</title>
</head>
<body>
  <script>
    // getOwnPropertyDescriptor()方法拦截 Object.getOwnPropertyDescriptor()
    // 返回一个属性描述对象或者undefined
    var handler = {
      getOwnPropertyDescriptor (target, key) {
        if (key[0] === '_') {
          return
        }
        return Object.getOwnPropertyDescriptor(target, key)
      }
    };
    var target = {_foo: 'bar', baz: 'tar'};
    var proxy = new Proxy(target, handler);
    Object.getOwnPropertyDescriptor(proxy, 'wat'); // undefined
    var a = Object.getOwnPropertyDescriptor(proxy, '_foo');//undefined 拦截成功
    console.log(a) // undefined
    var b = Object.getOwnPropertyDescriptor(proxy, 'baz');
    console.log(b)
    // configurable: true
    // enumerable: true
    // value: "tar"
    // writable: true
    // 上面代码中，handler.getOwnPropertyDescriptor()方法对于第一个字符为下划线的属性名会返回undefined。
  </script>
</body>
</html>